package com.ken.springcloud.service;

import com.ken.springcloud.anno.RemarkInfo;
import com.ken.springcloud.enums.UsedComponent;
import com.ken.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * <ul>
 * <li>Title: DeptClientServiceFallBackFactory</li>
 * <li>Description: TODO </li>
 * </ul>
 *
 * @author swc
 * @date 2021/8/28 11:50
 */
@RemarkInfo(usedComponent = {UsedComponent.Hystrix,UsedComponent.Feign}
,remark = "此部分为服务降级的例子 针对的是整个服务类=》FeignDeptService,说明服务降级是用在客户端 服务熔断用于服务端")
@Component
public class DeptClientServiceFallBackFactory implements FallbackFactory<FeignDeptClientService> {


    @Override
    public FeignDeptClientService create(Throwable throwable) {
        return new FeignDeptClientService() {
            @Override
            public boolean addDept(Dept dept) {
                return false;
            }

            @Override
            public Dept queryById(Long id) {
                return new Dept().setDeptNo(id).setDeptName("当前服务已被降级").setDbSource("this database is not found");
            }

            @Override
            public List<Dept> queryAll() {
                return new ArrayList<Dept>();
            }
        };
    }

}
